import { Module, Global } from '@nestjs/common';
import { HttpModule } from '@nestjs/axios';
import { JwtModule } from '@nestjs/jwt';
import { join } from 'path';
import { ConfigModule } from '@nestjs/config';
import { OnlyHttpModule } from './only-http/only-http.module';
import { FileMangerModule } from './file-manger/file-manger.module';
import { ScheduleModule } from '@nestjs/schedule';
// import config from './config';

const defaultConfig = () => ({
  isTest: process.env.NODE_ENV === 'test',
  isOnline: process.env.NODE_ENV === 'online',
  port: process.env.PORT,
  apiPrefix: process.env.API_PREFIX,
  domain: process.env.DOMAIN,
  staticPath: join(process.cwd(), '/static'),
  onlyoffice: {
    secret: process.env.ONLYOFFICE_SECRET,
    domain: process.env.ONLYOFFICE_DOMAIN,
    commandUrl: process.env.ONLYOFFICE_COMMAND_URL,
    callback: process.env.ONLYOFFICE_CALLBACK,
  },
});

@Global()
@Module({
  imports: [
    HttpModule,
    JwtModule,
    OnlyHttpModule,
    FileMangerModule,
    ScheduleModule.forRoot(),
    ConfigModule.forRoot({
      isGlobal: true,
      expandVariables: true,
      load: [defaultConfig],
    }),
  ],
  exports: [HttpModule, JwtModule, OnlyHttpModule, FileMangerModule],
  providers: [],
})
export class SharedModule {}
